package com.sicnu.estatemanagement.controller;

import com.github.pagehelper.Page;
import com.sicnu.estatemanagement.common.MessageConstant;
import com.sicnu.estatemanagement.common.PageResult;
import com.sicnu.estatemanagement.common.Result;
import com.sicnu.estatemanagement.common.StatusCode;
import com.sicnu.estatemanagement.domain.Letter;
import com.sicnu.estatemanagement.domain.Repair;
import com.sicnu.estatemanagement.service.LetterService;
import com.sicnu.estatemanagement.service.LetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Auth: zhuan
 * @Desc: 小区管理控制层:只负责接收前端浏览器发送的请求和请求参数，调用service层获取业务逻辑加工处理后的数据
 */
@RestController
@RequestMapping("/letter")
public class LetterController {

    @Autowired
    private LetterService LetterService;

    @RequestMapping("/find")
    public Result find(){
        List<Letter> all = LetterService.findAll();
        return new Result(false,200,"请求成功",all);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Letter> page = LetterService.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageConstant.COMMUNITY_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Letter letter){
        Boolean add = LetterService.add(letter);
        return new Result(add,StatusCode.OK,MessageConstant.COMMUNITY_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        Letter letter = LetterService.findById(id);
        return new Result(true,StatusCode.OK,MessageConstant.COMMUNITY_FIND_BY_ID_SUCCESS,letter);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Letter letter){
        Boolean add = LetterService.update(letter);
        return new Result(add,StatusCode.OK,MessageConstant.COMMUNITY_UPDATE_SUCCESS);
    }

    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean flag = LetterService.del(ids);
        return new Result(flag,StatusCode.OK,MessageConstant.COMMUNITY_DELETE_SUCCESS);
    }
}
